local DIY = require "packages/diy_utility/diy_utility"
local skel = fk.CreateSkill{
  name = "ym_water__jiefeng",
  tags = { DIY.ReadySkill }
}

Fk:loadTranslationTable{
  ["ym_water__jiefeng"] = "捷锋",
  [":ym_water__jiefeng"] = "蓄势技，结束阶段，你可以视为使用无距离限制的【杀】，"..
  "且你摸三张牌并将手牌弃置至三张，目标弃置所有手牌并摸三张牌。",

  ["#ym_water__jiefeng_choose"] = "捷锋：你可以视为使用无距离限制的【杀】，且你摸三张牌并将手牌弃置至三张，目标弃置所有手牌并摸三张牌。",

  ["$ym_water__jiefeng1"] = "且看此箭之下，焉有偷生之人？",
  ["$ym_water__jiefeng2"] = "君头已在此，还不授首来降！",
  ["$ym_water__jiefeng3"] = "哼！你我再斗一番，方知孰为霸王！",
  ["$ym_water__jiefeng4"] = "前番未见高下，此番定决生死！",
}

skel:addEffect(fk.EventPhaseEnd,{
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and target.phase == Player.Finish then
    --     玩家有技能                      玩家的回合            结束阶段
    return table.find(player.room:getOtherPlayers(player), function (p)
        return player:canUseTo(Fk:cloneCard("slash"), p, {bypass_distances = true, bypass_times = true})
        --存在玩家可以用杀的目标
      end)
    end
  end,
  audio_index = {1,2},
  anim_type = "offensive",
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(player.room:getOtherPlayers(player), function (p)
        return player:canUseTo(Fk:cloneCard("slash"), p, {bypass_distances = true, bypass_times = true})
        --哪些可以被玩家杀
      end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = skel.name,
      prompt = "#ym_water__jiefeng_choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    --动画
    room:doSuperLightBox("packages/water_wegame/qml/shitaishici.qml",{
      animIndex = 4
    })
    room:delay(1500)
    player.general = "ym_water__taishici4"
    room:broadcastProperty(player,"general")
    --摸三弃至三
    room:drawCards(player,3,skel.name)
    local n = player:getHandcardNum() - 3
    if n > 0 then
      player.room:askToDiscard(player, {
        min_num = n,
        max_num = n,
        include_equip = false,
        skill_name = skel.name,
        cancelable = false,
      })
    end
    --弃牌摸三
    to:throwAllCards("h", skel.name)
    room:drawCards(to,3,skel.name)
    --用杀
    local usecard = Fk:cloneCard("slash")
    usecard.skillName = skel.name
    if not player:canUseTo(usecard, to, {bypass_distances = true, bypass_times = true}) then return end
    room:useCard({
      from = player,
      card = usecard,
      tos = {to}
    })
  end,
})
skel:addEffect(DIY.SkillReadyFinish,{
  can_refresh = function (self, event, target, player, data)
    return data and data.who == player and data.skill.name == skel.name and not player.dead
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    --动画
    player:broadcastSkillInvoke(skel.name)
    room:doSuperLightBox("packages/water_wegame/qml/shitaishici.qml",{
      animIndex = 5
    })
    room:delay(1500)
    player.general = "ym_water__taishici5"
    room:broadcastProperty(player,"general")
  end,
})

return skel